home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / impression / sssort.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  87 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    sssort - 
  19.  *        Sort a sample set
  20.  *
  21.  *            Paul Haeberli - 1988
  22.  */
  23. #include "stdio.h"
  24. #include "ss.h"
  25. #include "math.h"
  26.  
  27. #define COLOR        1
  28. #define DIRECTION    2
  29. #define POSITION    4
  30. #define SIZE        8
  31.  
  32.  
  33. main(argc,argv)
  34. int argc;
  35. char **argv;
  36. {
  37.     sampleset *iss, *oss;
  38.     int i, mode;
  39.  
  40.     if( argc<4 ) {
  41.     fprintf(stderr,"usage: sssort in.ss out.ss [-c -d -p -s]\n");
  42.     exit(1);
  43.     } 
  44.     for(i=3; i<argc; i++) {
  45.     if(strcmp(argv[i],"-c") == 0)
  46.         mode |= COLOR;
  47.     if(strcmp(argv[i],"-d") == 0)
  48.         mode |= DIRECTION;
  49.     if(strcmp(argv[i],"-p") == 0)
  50.         mode |= POSITION;
  51.     if(strcmp(argv[i],"-s") == 0)
  52.         mode |= SIZE;
  53.     }
  54.     iss = ssfromfile(argv[1]);
  55.     oss = ssnew();
  56.     sssort(iss,oss,mode);
  57.     sstofile(argv[2],oss);
  58. }
  59.  
  60. sssort(iss,oss,mode)
  61. sampleset *iss, *oss; 
  62. int mode;
  63. {
  64.     sample *samptab[256];
  65.     sample *s, *ns;
  66.     int i, pos;
  67.  
  68.     for(i=0; i<256; i++)
  69.     samptab[i] = 0;
  70.     s = iss->head;
  71.     while(s) {
  72.     pos = s->at0;
  73.     ns = s->next;
  74.     s->next = samptab[pos];
  75.     samptab[pos] = s;
  76.     s = ns;
  77.     }
  78.     for(i=256; i--;) {
  79.     s = samptab[i];
  80.     while(s) {
  81.         ns = s->next;
  82.         addsample(oss,s);
  83.         s = ns;
  84.     }
  85.     }
  86. }
  87.